package com.doit.day05

object _01_剩下的算子 {
  def main(args: Array[String]): Unit = {

    //sortby
    val list: List[(Int, String, String, Int)] = List(
      (1, "zss", "语文", 80),
      (2, "lss", "语文", 20),
      (3, "前进", "语文", 90),
      (4, "小杨", "语文", 101),
      (5, "王总", "语文", 100)
    )

    //用reduceLeft 取分数最大的那个人
    val tuple: (Int, String, String, Int) = list.reduceLeft((a, b) => {
      if (a._4 < b._4) {
        a
      } else {
        b
      }
    })

    println(tuple)

    val tuples1: List[(Int, String, String, Int)] = list.dropWhile(_._1 > 2)//5
    val tuples2: List[(Int, String, String, Int)] = list.dropWhile(_._1 < 2)//4
    val tuples3: List[(Int, String, String, Int)] = list.dropWhile(_._1 < 3)//3
    val tuples4: List[(Int, String, String, Int)] = list.dropWhile(_._1 < 4)//2
    val tuples5: List[(Int, String, String, Int)] = list.dropWhile(_._1 < 5)//1
    println(tuples1.size)
    println(tuples2.size)
    println(tuples3.size)
    println(tuples4.size)
    println(tuples5.size)


    val list2: List[String] = List("hello", "hello", "hi")
    val map: Map[String, List[String]] = list2.groupBy(word => word)
    val res: Map[String, Int] = map.mapValues(_.size)
    println(res)


    val map1: Map[String, Int] = Map(
      ("wangzong", 750),
      ("lizong", 570),
      ("zhaozong", 456),
      ("qianzong", 356),
      ("sunzong", 654)
    )

    //各位总都是关系户，交钱了的，卷子的分数全部改成750
    val res1: Map[String, Int] = map1.mapValues(i => 750)

    map1.map(tp=>{
      val name: String = tp._1
      val score: Int = tp._2
      (name,750)
    })

    println(res1)

    //求语文成绩最高的那个人
    val max: (Int, String, String, Int) = list.max(new Ordering[(Int,String,String,Int)] {
      override def compare(x: (Int, String, String, Int), y: (Int, String, String, Int)) = x._4-y._4
    })
    println(max)


    println(list.maxBy(_._4))

    //排序
    val tuples: List[(Int, String, String, Int)] = list.sortBy(_._4)
    val maxScore: List[(Int, String, String, Int)] = tuples.reverse.take(1)
    println(maxScore(0))

    val list4: List[(Int, Int)] = List((1,2), (2,4), (6,3), (4,6))
    val list5: List[(Int, Int)] = List((6,9), (1,7), (2,8), (3,9))
    val tuples6: List[((Int, Int), (Int, Int))] = list4.zip(list5)

    val doubles: List[Double] = tuples6.map(tp => {
      //(1,2)
      val tp1: (Int, Int) = tp._1
      //(6,9)
      val tp2: (Int, Int) = tp._2
      Math.pow(Math.pow(tp2._1 - tp1._1, 2) + Math.pow(tp2._2 - tp1._2, 2), 0.5).formatted("%.2f").toDouble
    })
    println(doubles)


    val ints: List[Int] = List(2, 3, 4, 5, 6)
    val index: List[(Int, Int)] = ints.zipWithIndex
    println(index)//List((2,0), (3,1), (4,2), (5,3), (6,4))


    println(ints.slice(1, 4))//List(3, 4)

    val iterator: Iterator[List[Int]] = ints.sliding(3,1)
    for (elem <- iterator) {
      println(elem)
    }




//    val i: Int = list4.fold(10)((a,b)=>a+b)
//    println(i)


  }

}
